// 检查后端服务器状态的脚本
const http = require('http');

const checkBackend = () => {
  const options = {
    hostname: 'localhost',
    port: 5038,
    path: '/api/health', // 或者任何健康检查端点
    method: 'GET',
    timeout: 5000
  };

  const req = http.request(options, (res) => {
    console.log('✅ 后端服务器正在运行');
    console.log(`状态码: ${res.statusCode}`);
    console.log(`状态消息: ${res.statusMessage}`);
  });

  req.on('error', (err) => {
    if (err.code === 'ECONNREFUSED') {
      console.log('❌ 后端服务器未启动 (localhost:5038)');
      console.log('请启动后端API服务器后再试');
    } else {
      console.log('❌ 连接错误:', err.message);
    }
  });

  req.on('timeout', () => {
    console.log('❌ 连接超时');
    req.destroy();
  });

  req.end();
};

console.log('正在检查后端服务器状态...');
checkBackend();
